package com.mr.web.support;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.validation.DataBinder;
public class RequestMapDataBinder extends DataBinder {
   private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
   private static SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
   private static CustomDateEditor dateEditor = new CustomDateEditor(dateFormat, true);
   private static CustomTimestampEditor timestampEditor = new CustomTimestampEditor(true);
   static{
      dateFormat.setLenient(false);
      timestampFormat.setLenient(false);
   }
   public RequestMapDataBinder(Object target) {
      super(target);
      this.registerCustomEditor(Date.class, null, dateEditor);
      this.registerCustomEditor(Timestamp.class, null, timestampEditor);
   }

   public RequestMapDataBinder(Object target, String objectName) {
      super(target, objectName);
      this.registerCustomEditor(Date.class, null, dateEditor);
      this.registerCustomEditor(Timestamp.class, null, timestampEditor);
   }

   public void bind(Map dwrRequestMap) {
      MutablePropertyValues mpvs = new RequestMapPropertyValues(dwrRequestMap);
      doBind(mpvs);
   }
}
